<template>
  <div class="proDialog">
    <el-dialog title="选择套餐卡" :visible.sync="visible" width="1000px" z-index="1500" append-to-body @close="toCancelBox">
      <el-form class="formList" :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch"
        label-width="100px" style="padding-top: 0">

        <el-form-item label="套餐卡名称" prop="cardName">
          <el-input v-model="queryParams.cardName" placeholder="请输入套餐卡名称" clearable size="small" />
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        </el-form-item>
      </el-form>

      <el-table border ref="indexTable" :data="infoList" tooltip-effect="dark" style="width: 100%"
        @row-click="singleElection">

        <el-table-column label="" width="40">
          <template slot-scope="scope">
            <el-radio class="radio" v-model="templateSelection" :label="scope.$index">&#12288;</el-radio>
          </template>
        </el-table-column>

        <el-table-column label="套餐卡主图" align="center" prop="cardMainImage" width="130">
          <template slot-scope="scope">
            <el-image v-if="scope.row.cardMainImage != null && scope.row.cardMainImage != ''" slot="reference"
              :src="scope.row.cardMainImage" class="image-rows" :preview-src-list="[scope.row.cardMainImage]">
            </el-image>
          </template>
        </el-table-column>
        <el-table-column label="套餐卡名称" align="left" prop="cardName" width="240">
          <template slot-scope="scope">
            <a style="color: #1890ff;" @click="handledetail(scope.row)">{{ scope.row.cardName }}
            </a>
          </template>
        </el-table-column>
        <el-table-column label="面价" align="center" prop="cardPriceStr" sortable width="100" />
        <el-table-column label="活动价格" align="center" prop="cardFavorablePriceStr" sortable width="100" />
        <el-table-column label="结算价格" align="center" prop="cardSettlementPriceStr" sortable width="100" />
        <el-table-column label="项目类别" align="center" prop="cardTypeStr" width="100" />
        <el-table-column label="是否投放门店" align="center" prop="isCommon">
          <template slot-scope="scope">
            <span>{{ scope.row.isCommon == '1' ? '通用' : '指定门店' }}</span>
          </template>
        </el-table-column>

      </el-table>

      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" :page-sizes="pageSizess" />

      <div style="display:flex; justify-content: flex-end;">
        <el-button @click="determine" type="primary">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>

// import {
//   listCoupon,
//   getCoupon,
//   delCoupon,
//   addCoupon,
//   updateCoupon,
//   updateStatus,
//   getCouponRule,
//   addCouponRule,
//   updateCouponRule
// } from "@/api/activity/coupon";
import {
  listProboxServiceCard, updateStatus, updateRecommend, listStoreByItemId, isSaveByList, isSaveDeviceByList, listDeviceByItemId,
  addOrUpdateCompose, listComposeByItemId
} from "@/api/service/card"
export default {
  props: {
    flag: {
      type: Boolean,
    },

  },
  watch: {
    flag(val) {
      this.visible = this.flag;
    },
  },
  data() {
    return {
      templateSelection: '',
      // 显示搜索条件
      showSearch: true,
      datas: null,
      selectedDatas: [],
      pageSizess: [5, 10, 15, 20, 25, 30, 50],
      // 商品信息表格数据
      infoList: [],
      // indexTable: [],
      infoListHistory: [],
      multipleSelection: [],
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 5,
        storeName: null,
        dataStatus: '1',
      },
      visible: false,
      categoryOptions: [],
      multipleSelectionData: {},
    };
  },
  created() {
    this.visible = this.flag;
    this.getList();

  },
  methods: {
    singleElection(row) {
      this.multipleSelectionData = row;
      this.templateSelection = this.infoList.indexOf(row);
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    toCancelBox() {
      this.visible = false;
      this.$emit("toCloseBox", false);
    },
    //回显选中
    greet(selectedData) {
      if (Object.keys(selectedData).length > 0) {
        this.multipleSelectionData = selectedData;
      } else {
        this.multipleSelectionData = {};
      }
      this.singleElection(this.multipleSelectionData)
    },

    /** 确定选择商品 */
    determine() {
      this.$emit("multipleSelection", this.multipleSelectionData);

      this.$forceUpdate();
      this.open = false;
    },
    /** 查询商品信息列表 */
    getList() {
      listProboxServiceCard(this.queryParams).then((response) => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
        if (Object.keys(this.multipleSelectionData).length > 0) {
          setTimeout(() => {
            let index = -1;
            this.infoList.forEach((vo, ind) => {
              if (this.multipleSelectionData.cardId == vo.cardId) {
                index = ind
              }
            })
            this.templateSelection = index;
          });

        }


      });
    },
  },
};
</script>
<style scoped>
.determine {
  position: relative;
  color: #fff;
}

.pagination-container {
  position: relative;
}

.image-rows {
  width: 80px;
  height: 80px;
}

/deep/ .el-radio__label {
  display: none;
}
</style>
